package com.study.hadoop.weather;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author stephen
 * @create 2019-01-10 21:09
 * @since 1.0.0
 */
public class Weather implements WritableComparable<Weather> {

    private int year;

    private int month;

    private int day;

    private int temp;

    @Override
    public int compareTo(Weather o) {
        // 日期正序
        int y = Integer.compare(this.year,o.getYear()) ;
        if(y == 0){
            int m = Integer.compare(this.month, o.getMonth());
            if(m == 0){
                return Integer.compare(this.day,o.getDay()) ;
            }
            return m;
        }
        return y;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.write(year);
        out.write(month);
        out.write(day);
        out.write(temp);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.year = in.readInt();
        this.month = in.readInt();
        this.day = in.readInt();
        this.temp = in.readInt();
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getTemp() {
        return temp;
    }

    public void setTemp(int temp) {
        this.temp = temp;
    }
}
